<template>
  <h1>循环指令</h1>
  <ul v-for="item in 3">
    <li>hello</li>
    <li>hello</li>
    <li>hello</li>
  </ul>
  <hr>
  <ul>
    <li v-for="item in 3">{{item}}</li>
  </ul>
  <ul>
    <li v-for="p in productArr">{{p}}</li>
  </ul>
  <table border="1">
    <tr>
      <th>商品编号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品库存</th>
      <th>操作</th>
    </tr>
  <tr v-for="(item,index) in productArr">
    <td>{{index+1}}</td>
    <td>{{item.title}}</td>
    <td>{{item.price}}</td>
    <td>{{item.num}}</td>
    <td><button @click="del(index)">删除</button></td>
  </tr>
  </table>

</template>


<script setup>
  import {ref} from "vue";
  const del = (index) => {
    productArr.value.splice(index,1)
  }

  const productArr = ref([
    {title:"苹果手机",price:3000,num:600},
    {title:"三星手机",price:5000,num:200},
    {title:"小米手机",price:4000,num:400},
    {title:"华为手机",price:7000,num:300}
  ])
</script>


<style scoped>

</style>